<?php
defined('IN_IA') or exit('Access Denied');

global $_W, $_GPC;
$op = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
//咨询列表页
if ($op == 'display') {
    $pindex = max(1, intval($_GPC['page']));
    $psize = 10;
    $condition = " uniacid = '{$_W['uniacid']}'";
    $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('aide_form_data_recruit') . " WHERE $condition");
    $recruit=pdo_fetchall("SELECT * FROM " . tablename('aide_form_data_recruit') . " WHERE uniacid='{$_W['uniacid']}' AND is_confirm=1 ORDER BY id DESC LIMIT " . ($pindex - 1) * $psize . ',' . $psize);
    //记录总数
    $pager = pagination($total, $pindex, $psize);
    include aide_template ('recruit');
    exit;
}
if ($op == 'post') {
    $recruitid = intval($_GPC['recruitid']);
    $recruit=pdo_fetchall("SELECT * FROM " . tablename('aide_form_data_recruit') . " WHERE id=$recruitid ORDER BY  id ASC LIMIT 1");
    $recruit=$recruit[0];
    $recruit['picnum']=explode(',',$recruit['picnum']);
    if (checksubmit('submit')) {
        $form = $_GPC['recruit'];
        $data['is_pass'] = $form['is_pass'];
        pdo_update ('aide_form_data_recruit', $data, array ('id' => $recruitid));
        message ('更新成功！', web_url('recruit/recruit/display'), 'success');
    }
    include aide_template ('recruit');
    exit;
}
if ($op == 'delete') {
    $recruitid = intval($_GPC['recruitid']);
    pdo_delete ('aide_form_data_recruit', array ('id' => $recruitid));
    die(json_encode(array("errno" => 0,'message'=>'删除成功')));
    exit;
}
if ($op == 'pass' && $_W['isajax']) {
    $id = $_GPC['id'];
    $state = (int)$_GPC['state'];
    $reason = $_GPC['reason'];
    $arr=['is_pass'=>$state,'reason'=>$reason];
    $result = pdo_update ('aide_form_data_recruit', $arr, array ('id' => $id));
    die(json_encode(array('result'=>$result,)));
}
